/**
import { Info } from '@/components/Info';
 * Created by Administrator on 2018/11/3.
 */
var User = require("../models/users");
/**
 * 注册
 */

module.exports = function (data, response) {

  let user = new User({
    username: data.username, //用户账号
    company: data.company,
    pass: data.pass, //密码
  });
  let wherestr = {
    'username': data.username
  };

  User.find(wherestr, function (err, res) {
    if (err) {
      console.log("Error:" + err);
    }
    res.length !== 0 && response.json({
      status: 1,
      data: {
        msg: '该用户名已被注册'
      }
    });

    res.length === 0 && user.save(function (err, res) {
      if (err) {
        console.log("Error:" + err);
      } else {
        response.json({
          status: 0,
          data: {
            msg: '注册成功'
          }
        });
      }
    });

  })
}
